package com.dc.system.serviceImpl;

import com.dc.base.utils.MD5Util;
import com.dc.common.model.BaseModel;
import com.dc.system.mapper.UserMapper;
import com.dc.system.model.SysUser;
import com.dc.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    public UserMapper userMapper;

    @Override
    public BaseModel<SysUser> login(SysUser user, BaseModel baseModel) {
        if (user == null){
            baseModel.setMessage("用户名和密码不允许为空！");
        }else if ("".equals(user.getPassword())){
            baseModel.setMessage("密码不允许为空！");
        }
        //把明文密码转换成密文
        user.setPassword(MD5Util.md5(user.getPassword()));
        SysUser sysUser = userMapper.getUserByPassAndName(user);
        if (sysUser == null){
            baseModel.setMessage("用户名或密码错误！");
        }else {
            baseModel.setMessage("登陆成功！");
            baseModel.setData(sysUser);
            baseModel.setCode(0);
        }
        return baseModel;
    }
}
























